#ifndef CLUSNET_NET_SYNCTCPCLIENT_H
#define CLUSNET_NET_SYNCTCPCLIENT_H

#include <boost/asio.hpp>
#include <chrono>
#include "Callbacks.h"
#include "TcpDataPacket.h"

namespace clusnet
{
namespace net
{

class SyncTcpClient final
{
    public:
        SyncTcpClient();
        ~SyncTcpClient();
        SyncTcpClient(SyncTcpClient const&) = delete;
        SyncTcpClient& operator= (SyncTcpClient const&) = delete;

    public:
        void connect(boost::system::error_code&, char const* host, char const* port, std::chrono::steady_clock::duration const& timeout = std::chrono::seconds(0));
        TcpUniqDataPacketPtr read(boost::system::error_code&, std::chrono::steady_clock::duration const& timeout = std::chrono::seconds(0));
        size_t write(boost::system::error_code&, TcpDataPacketPtr& data, std::chrono::steady_clock::duration const& timeout = std::chrono::seconds(0));
        void close();

    private:
        void run(boost::system::error_code&, std::chrono::steady_clock::duration const& timeout);

    private:
        boost::asio::io_context         io_;
        boost::asio::ip::tcp::socket    socket_;
};
}
}

#endif 
